﻿<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
                    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
                    xmlns:markup="clr-namespace:Elysium.Markup"
                    xmlns:params="clr-namespace:Elysium.Parameters"
                    xmlns:primitives="clr-namespace:Elysium.Controls.Primitives"
                    xmlns:controls="clr-namespace:Elysium.Controls">

    <ResourceDictionary.MergedDictionaries>
        <ResourceDictionary Source="pack://application:,,,/Themes/SharedResources.xaml"/>
        <ResourceDictionary Source="pack://application:,,,/Themes/Buttons/CommandButtonBase.Normal.xaml"/>
        <ResourceDictionary Source="pack://application:,,,/Themes/Buttons/DropDownCommandButton.Submenu.xaml"/>
    </ResourceDictionary.MergedDictionaries>
    
    <Style x:Key="{x:Type controls:DropDownCommandButton}" TargetType="{x:Type controls:DropDownCommandButton}" BasedOn="{StaticResource {x:Type primitives:CommandButtonBase}}">
        <Style.Resources>
            <Style TargetType="{x:Type controls:Submenu}" BasedOn="{StaticResource DropDownCommandButtonSubmenuStyle}"/>
        </Style.Resources>
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="{x:Type controls:DropDownCommandButton}">
                    <Grid Background="{markup:ThemeResource TransparentBrush}"
                          TextBlock.Foreground="{TemplateBinding Foreground}"
                          TextBlock.FontFamily="{TemplateBinding FontFamily}"
                          TextBlock.FontSize="{TemplateBinding FontSize}"
                          TextBlock.FontStretch="{TemplateBinding FontStretch}"
                          TextBlock.FontStyle="{TemplateBinding FontStyle}"
                          TextBlock.FontWeight="{TemplateBinding FontWeight}"
                          TextOptions.TextFormattingMode="{TemplateBinding TextOptions.TextFormattingMode}"
                          TextOptions.TextRenderingMode="{TemplateBinding TextOptions.TextRenderingMode}"
                          RenderOptions.ClearTypeHint="{TemplateBinding RenderOptions.ClearTypeHint}"
                          SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}">
                        <Grid.RowDefinitions>
                            <RowDefinition Height="*"/>
                            <RowDefinition Height="Auto"/>
                        </Grid.RowDefinitions>
                        <Ellipse x:Name="PART_Decor"
                                 Grid.Row="0"
                                 Fill="{TemplateBinding Background}"
                                 Stroke="{TemplateBinding BorderBrush}"
                                 StrokeThickness="{Binding BorderThickness, RelativeSource={RelativeSource TemplatedParent}, Converter={StaticResource ThicknessToDoubleConverter}}"
                                 Stretch="Fill"
                                 HorizontalAlignment="Center"
                                 VerticalAlignment="Center"/>
                        <ContentPresenter x:Name="PART_ContentHost"
                                          Grid.Row="0"
                                          Content="{TemplateBinding Content}"
                                          ContentStringFormat="{TemplateBinding ContentStringFormat}"
                                          ContentTemplate="{TemplateBinding ContentTemplate}"
                                          ContentTemplateSelector="{TemplateBinding ContentTemplateSelector}"
                                          Margin="{TemplateBinding Padding}"
                                          RecognizesAccessKey="True"
                                          HorizontalAlignment="Center"
                                          VerticalAlignment="Center"/>
                        <ContentPresenter x:Name="PART_HeaderHost"
                                          Grid.Row="1"
                                          Content="{TemplateBinding Header}"
                                          ContentStringFormat="{TemplateBinding HeaderStringFormat}"
                                          ContentTemplate="{TemplateBinding HeaderTemplate}"
                                          ContentTemplateSelector="{TemplateBinding HeaderTemplateSelector}"
                                          Margin="{TemplateBinding Padding}"
                                          HorizontalAlignment="Center"/>
                        <Popup x:Name="PART_Popup"
                               Grid.Row="1"
                               AllowsTransparency="True"
                               IsOpen="{Binding RelativeSource={RelativeSource TemplatedParent}, Path=IsDropDownOpen, Mode=TwoWay}"
                               StaysOpen="False"
                               Placement="Custom"
                               VerticalOffset="{TemplateBinding params:General.BoldPaddingValue}"
                               MaxHeight="{TemplateBinding MaxDropDownHeight}"/>
                    </Grid>
                    <ControlTemplate.Triggers>
                        <Trigger Property="Header" Value="{x:Null}">
                            <Setter TargetName="PART_HeaderHost" Property="Visibility" Value="Collapsed"/>
                        </Trigger>
                    </ControlTemplate.Triggers>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
        <Style.Triggers>
            <MultiTrigger>
                <MultiTrigger.Conditions>
                    <Condition Property="IsDropDownOpen" Value="True"/>
                    <Condition Property="params:Animation.Type" Value="None"/>
                </MultiTrigger.Conditions>
                <MultiTrigger.Setters>
                    <Setter Property="BorderBrush" Value="{markup:ThemeResource NormalBrush}"/>
                    <Setter Property="params:CommandButtons.Mask" Value="{markup:ThemeResource NormalBrush}"/>
                </MultiTrigger.Setters>
            </MultiTrigger>
            <MultiTrigger>
                <MultiTrigger.Conditions>
                    <Condition Property="IsDropDownOpen" Value="True"/>
                    <Condition Property="params:Animation.Type" Value="Fade"/>
                </MultiTrigger.Conditions>
                <MultiTrigger.EnterActions>
                    <BeginStoryboard>
                        <Storyboard>
                            <ColorAnimation Storyboard.TargetProperty="BorderBrush.(SolidColorBrush.Color)"
                                            Duration="{markup:ThemeResource OptimumDuration}"
                                            To="{markup:ThemeResource NormalColor}"/>
                            <ColorAnimation Storyboard.TargetProperty="(params:CommandButtons.Mask).(SolidColorBrush.Color)"
                                            Duration="{markup:ThemeResource OptimumDuration}"
                                            To="{markup:ThemeResource NormalColor}"/>
                        </Storyboard>
                    </BeginStoryboard>
                </MultiTrigger.EnterActions>
            </MultiTrigger>
        </Style.Triggers>
    </Style>

</ResourceDictionary>